#!/bin/sh
# market_cap_top50.sh
# 
#
# Created by ［CGM］sgxiao on 08-12-15.
# Copyright 2008 CGM. All rights reserved.
# history
#	sgxiao	0.5	add a new parameters for check the count of top
#	sgxiao	0.4	add to_array.sh submodule
#	sgxiao	0.3	add all.top50.sh
#	sgxiao	0.2	add makefile
#############################


startYear=1994
endYear=2008
DATA=data
RESULT=result.doc
filename=$1
AWKSRC=market_cap_top50.awk
PRICEVOLUME=temp.top50
PRICEVOLUME1=top50

#mkdir ${PRICEVOLUME1}

#the nearest available date of Jan
header[1994]="0103"
header[1995]="0103"
header[1996]="0102"
header[1997]="0102"
header[1998]="0105"
header[1999]="0104"
header[2000]="0104"
header[2001]="0102"
header[2002]="0104"
header[2003]="0102"
header[2004]="0102"
header[2005]="0104"
header[2006]="0104"
header[2007]="0104"
header[2008]="0102"

make

while [ ${startYear} -le ${endYear} ] 
do
	echo ${startYear}
echo "BEGIN {
	FS=\"\\\\t\"
}
\$1 ~ /${startYear}${header[startYear]}/{
	print \$2, \$(15)
}
END{}
" > ${AWKSRC}

	awk -f ${AWKSRC} ${startYear}.${DATA} >  ${startYear}.${PRICEVOLUME}
	
	# a new parameters for check the count of top, now is the top50
	java MarketCapTop50 ${startYear}.${PRICEVOLUME} 5 >  ${startYear}.${PRICEVOLUME1}
	startYear=$((startYear + 1))
done

rm *.${PRICEVOLUME}
mv *.data ../
#mv *.${PRICEVOLUME1} ./${PRICEVOLUME1}/

./all.top50.sh
./to_array.sh
